import React, { Component } from 'react';
import {
  Card,
  Button,
  Table,
  Menu,
  Input,
  Divider,
  Popconfirm,
  Modal,
  message,
  Radio
} from 'antd';
import { connect } from 'dva';
import PropTypes from 'prop-types';
import styles from '../index.less';
import { getOwner } from '@/utils/authority';


const namespace = 'Inventory';
const RadioButton = Radio.Button;
const RadioGroup = Radio.Group;
const { Search, TextArea } = Input;

const mapStateToProps = state => {
  const list = state[namespace].supplierList;
  const isLoading = state[namespace].supplierLoading;
  return {
    list,
    isLoading,
  };
};

const mapDispatchToProps = dispatch => {
  return {
    getList: () => {
      const action = {
        type: `${namespace}/querySupplier`,
        payload: {
          owner: getOwner(),
        },
      };
      dispatch(action);
    },
  };
};

@connect(
  mapStateToProps,
  mapDispatchToProps
)
export default class SelectCategory extends Component {
  constructor(props) {
    super(props);
  }

  static propTypes  = {
    onSelect: PropTypes.func.isRequired,
  }

  componentDidMount() {
    this.reloadData();
  }

  reloadData = (params) => {
    this.props.getList();
  }

  handleSelect = (record) => {
    this.props.onSelect(record);
  }

  render() {
    const { isLoading, list } = this.props;

    const columns = [
      {
        title: '供应商',
        dataIndex: 'suppliercompanyname',
        key: 'suppliercompanyname',
      },
      {
        title: '联系人',
        dataIndex: 'managername',
        key: 'managername',
        width: 150,
      },
      {
        title: '手机号',
        dataIndex: 'tel',
        key: 'tel',
        width: 150,
      },
    ];


    return (
      <div>
        <Table
          bordered
          columns={columns}
          loading={isLoading}
          dataSource={list}
          rowKey="_id"
          pagination={false}
          onRow={record => {
            return {
              onClick: () => this.handleSelect(record), // 点击行
            };
          }}
        />
      </div>
    );
  }
}